// 导入defineStore
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '@/types/user.d.ts'

export const useUserStore = defineStore(
  'user',
  () => {
    // 1.定义user数据
    const user = ref<User>()
    // 2.设置user
    const setUser = (val: User) => {
      user.value = val
    }
    // 3.清空user
    const delUser = () => {
      user.value = undefined
    }
    // 4.所有的数据方法都要return
    return {
      user,
      setUser,
      delUser
    }
  },
  {
    persist: true
  }
)
